<!--
 * @Descripttion: 
 * @Author: zhanyi
 * @Date: 2021-10-27 14:14:37
 * @FilePath: \wczd-mobile\src\pages\archives\archives.vue
-->
<template>
  <div class="safeCheck">
    <div class="globalTitle">
      <div class="top-panel-cont">
        <image class="_image_icon" @click="back" src="@/static/wczd/back.png" alt=""></image>
        <div class="title">安全检查结果</div>
      </div>
      <div class="archives">
        <!-- <SearchBar placeholder="请输入关键字搜索" cancelButton="none" v-model="searchValue" :radius="5" /> -->

      </div>
      <div v-if="form.inspectState==='0'" class="addBtn" @click="handleAdd">添加结果</div>
    </div>
    <div class="globalTitle-describe">
      <p>被检查单位：{{form.safeCompanyName}}</p>
      <p>带队领导：{{form.leader}}</p>
      <p>参与人员：{{form.member}}</p>
      <!-- <p>未确认结果：{{needAgreePerson(form)||'无'}}</p> -->
      <p>检查时间：{{form.findTime}}</p>
    </div>
    <zPaging class="_sxwh_box" :default-page-size="10" :fixed='false' :height="'100%'" ref="paging" @query="queryList" v-model="jobManagerData" :delay='200' :refresher-end-bounce-enabled="false">
      <div class="_box_item" v-for="(item,index) in jobManagerData" :key="index">
        <div class="_title">
          <div class="_left">{{item.title||item.dis||'隐患/意见'}}</div>
          <!-- <div class="_right" :class="_isTextColor(item)">{{_isDanger(item)}}</div> -->
        </div>
        <div class="_center">
          <div class="_center_item">
            <div class="_left">类型</div>
            <div class="_right">{{item.type==='0'?'隐患':'意见'}}</div>
          </div>
          <div class="_center_item">
            <div class="_left">上报时间</div>
            <div class="_right">{{item.createTime}}</div>
          </div>
        </div>
        <div class="_footer" @click="_goInfo(item)">
          <div class="_left">
            详情
          </div>
          <div class="_right">
            <image class="_image_icon" src="@/static/wczd/more.png" alt="">
          </div>
        </div>
      </div>
    </zPaging>
    <!--  -->
    <!-- <button v-if="form.needAgree==='1'" style="width:90%" type="primary" @click="feedSubmitForm">结果确认</button> -->
    <br>
  </div>
</template>

<script>
import SearchBar from "@/components/uni-search-bar/uni-search-bar.vue";
import {
  safeInspectResList,
  safeInspectCompanyOne,
  safeInspectCompanyFeedback,
} from "@/api/safeCheck";
import zPaging from '@/uni_modules/z-paging/components/z-paging/z-paging.vue'
import ZPagingMixin from '@/uni_modules/z-paging/components/z-paging/js/z-paging-mixin'
import customNomore from '@/pages/component/custom-nomore/custom-nomore.vue'
import moment from "moment";

export default {
  name: 'archives',
  components: { SearchBar, zPaging, customNomore },
  mixins: [ZPagingMixin],
  data () {
    return {
      searchValue: "",
      jobManagerData: [],
      safeCompanyId: null,
      resCompanyId: null,
      inspectId: null,
      safeCompanyName: null,
      form: {}
    }
  },
  watch: {
    searchValue () {
      this.queryList(1, 10)
    }
  },
  onLoad: function (option) {
    this.resCompanyId = option.id
    this.safetyCheckOne(option.id)
  },
  onShow () {
    this.queryList(1, 10)
    this.safetyCheckOne(this.resCompanyId)
  },
  computed: {
    needAgreePerson () {
      return function (row) {
        const person = row.leader ? row.leader.split(',') : []
        const personId = row.leaderId ? row.leaderId.split(',') : []
        const member = row.member ? row.member.split(',') : []
        const memberId = row.memberId ? row.memberId.split(',') : []
        const agreeMemberId = row.agreeMemberId ? row.agreeMemberId.split(',') : []
        const name = []
        for (let i = 0; i < memberId.length; i++) {
          if (personId.indexOf(memberId[i]) < 0) {
            personId.push(memberId[i])
            person.push(member[i])
          }
        }
        for (let i = 0; i < personId.length; i++) {
          if (agreeMemberId.indexOf(personId[i]) < 0) {
            name.push(person[i].split('(')[0])
          }
        }
        return name.join(',')
      }
    },
  },
  methods: {
    // 结果确认 按钮
    feedSubmitForm () {
      uni.navigateTo({
        url: `/pages/safeCheck/safeCheckConfirm?id=${this.form.id}`,
      })
      // const id = this.form.id
      // safeInspectCompanyFeedback({
      //   id: id,
      //   needProgramme: this.form.needProgramme,
      //   needReunite: this.form.needReunite,
      //   remark: this.form.remark
      // }).then((response) => {
      //   this.queryList(1, 10)
      //   this.msgSuccess('反馈成功')
      // })
    },
    // 重置表单
    reset () {
      this.form = {
        agreeMemberId: null,
        companyId: null,
        companyName: null,
        inspectTime: null,
        leader: null,
        leaderId: null,
        member: null,
        memberId: null,
        name: null,
        safeCompany: null,
        safeCompanyParse: null,
        safeCompanyIds: null,
        safeCompanyIdsParse: null,
        status: null,
        safeCompanyName: null,
        findTime: null,
        needAgree: null,
        inspectState: null,
      }
    },
    // 安全检查单条
    safetyCheckOne (id) {
      this.reset()
      safeInspectCompanyOne({ id: id }).then(response => {
        if (response.code === 200) {
          for (const d in this.form) {
            this.form[d] = response.data[d]
          }
          this.form.id = id
          this.form['safeCompanyParse'] = response.data.safeCompany?.split(',') || []
          this.form['safeCompanyIdsParse'] = response.data.safeCompanyIds?.split(',') || []
        }
      })
    },
    handleAdd () {
      uni.navigateTo({
        url: `/pages/safeCheck/safeCheck-edit?resCompanyId=${this.resCompanyId}&safeCompanyId=${this.safeCompanyId}&inspectId=${this.inspectId}&safeCompanyName=${this.safeCompanyName}`,
      })
    },
    // z-paging 查询方法
    queryList (pageNo, pageSize) {
      uni.showLoading({
        title: '加载中'
      });
      safeInspectResList({ title: this.searchValue, resCompanyId: this.resCompanyId }, { pageNum: pageNo, pageSize: pageSize }).then(res => {
        this.$refs.paging.complete(res.rows);
        uni.hideLoading();
      })
    },
    back () {
      uni.navigateBack({
        delta: 1
      });
    },
    _goInfo (item) {
      uni.navigateTo({
        url: `/pages/safeCheck/safeCheck-detail?id=${item.id}&inspectState=${this.form.inspectState}`,
      })
    }
  },
}
</script>

<style scoped lang="scss">
.safeCheck {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.globalTitle {
  position: fixed;
  background: #fff;
  z-index: 99;
  height: 120upx;
  .addBtn {
    position: absolute;
    right: 40upx;
    top: 30upx;
    padding: 6upx 16upx;
    background-color: #ffb500;
    border-radius: 10upx;
    color: #fff;
  }
  .title {
    width: 60%;
  }
}
._sxwh_box {
  flex: 1;
  height: 0;
}
.title {
  padding-left: 0;
}
.top-panel-cont {
  display: flex;
  align-items: center;
  image {
    margin-left: 30upx;
    margin-top: 20upx;
    width: 56upx;
    height: 56upx;
  }
  div {
    font-size: 40upx;
    font-weight: bold;
  }
}
.archives {
  position: absolute;
  padding: 0 30upx 0 40upx;
  width: 100%;
  margin-top: 0;
  bottom: 0upx;
  p {
    font-size: 28upx;
  }
}
.globalTitle-describe {
  padding-top: 150upx;
  background-color: #fff;
  p {
    padding: 0 30upx 0 40upx;
    line-height: 80upx;
    font-size: 28upx;
    border-bottom: 1px rgb(236, 236, 236) solid;
  }
}
</style>
